package org.snaker.engine.parser.logicflow;


import org.snaker.engine.parser.AbstractNodeParser;
import org.snaker.engine.parser.logicflow.model.LogicFlowData;

import java.util.Objects;

public abstract class LogicFlowJSONAbstractNodeParser extends AbstractNodeParser<LogicFlowData.Node> {


    /**
     * 实现NodeParser接口的parse函数
     * 由子类产生各自的模型对象，设置常用的名称属性，并且解析子节点transition，构造TransitionModel模型对象
     */
    public void parse(LogicFlowData.Node node) {
        nodeModel = newModel();
        nodeModel.setName(node.getId());
        if(Objects.nonNull(node.getText())) {
            nodeModel.setDisplayName(node.getText().getValue());
        }
        nodeModel.setLayout(node.getLayout());
        nodeModel.setPreInterceptors(node.getProperties().get(ATTR_PREINTERCEPTORS));
        nodeModel.setPostInterceptors(node.getProperties().get(ATTR_POSTINTERCEPTORS));
        parseNode(nodeModel, node);
    }
}
